
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author DoanMinhVu
 */
public class MenuGame extends Canvas {

    private MidletDuaXe midlet;
    private Image imgBackGround,imgMainMenu,imgNewGameBG,imgHighScoreBG,imgOptionBG,imgExitBG,imgHelpBG,imgNew,imgHigh,imgOption,imgHelp,imgExit;
    private int select=1;
    private Display display;
    SoundHelper soundHelper;

    public MenuGame(MidletDuaXe midlet,Display display){
        this.midlet = midlet;
        this.display = display;
        setFullScreenMode(true);
        soundHelper = new SoundHelper("Sound/california_dreaming.mid");
        soundHelper.setLoopCount(1);
        soundHelper.playSound();
    }

 
    protected void keyPressed(int keyCode){
        String keyText = getKeyName(keyCode);
        switch(getGameAction(keyCode)){
            case UP:
                if(select==1){
                    select = 4;
                }else{
                    select--;
                }
                repaint();
                break;
            case DOWN:
                if(select==4){
                    select = 1;
                }else{
                    select++;
                }
                repaint();
                break;
            case FIRE:
                if(select==1){
                    midlet.showPlayGame();
                }
                 if(select==2){
                    midlet.showHighScore();
                }
//                 if(select==3){
//                    midlet.showMenuGame();
//                }
                 if(select==3){
                    midlet.showHelp();
                }
                 if(select==4){
                    midlet.showExit();
                 }
                repaint();
                soundHelper.stopSound();
                break;
        }
    }

    protected void paint(Graphics g) {
        try{
            imgBackGround = Image.createImage("/Images/menuBG.png");
            imgMainMenu = Image.createImage("/Images/MenuNew.png");
//            imgNewGameBG = Image.createImage("/Images/NewGameBG.png");
//            imgHighScoreBG = Image.createImage("/Images/HighScoreBG.png");
//            imgOptionBG = Image.createImage("/Images/OptionBG.png");
//            imgHelpBG = Image.createImage("/Images/HelpBG.png");
//            imgExitBG = Image.createImage("/Images/ExitBG.png");
            imgNew = Image.createImage("/Images/NewGame_1.png");
            imgHigh = Image.createImage("/Images/HighScore_1.png");
            imgHelp = Image.createImage("/Images/Help_1.png");
            imgExit= Image.createImage("/Images/Exit_1.png");
        }
        catch(Exception ex){
            System.out.print(ex.toString());
        }
        g.drawImage(imgBackGround, getWidth()/2, getHeight()/2,g.HCENTER|g.VCENTER);
//        g.drawImage(imgNewGameBG, getWidth()/2,getHeight()/2-90, g.HCENTER|g.VCENTER);
//        g.drawImage(imgHighScoreBG, getWidth()/2,getHeight()/2-45, g.HCENTER|g.VCENTER);
//        g.drawImage(imgOptionBG, getWidth()/2,getHeight()/2, g.HCENTER|g.VCENTER);
//        g.drawImage(imgHelpBG, getWidth()/2,getHeight()/2+45, g.HCENTER|g.VCENTER);
//        g.drawImage(imgExitBG, getWidth()/2,getHeight()/2+90, g.HCENTER|g.VCENTER);
        g.drawImage(imgMainMenu, getWidth()/2, getHeight()/2+40,g.HCENTER|g.VCENTER);
        g.setColor(100, 100, 100);
        if(select==1){
            g.drawImage(imgNew, getWidth()/2,getHeight()/2-19, g.HCENTER|g.VCENTER);
        }
        if(select==2){
            g.drawImage(imgHigh, getWidth()/2,getHeight()/2+20, g.HCENTER|g.VCENTER);
        }
//        if(select==3){
//            g.drawImage(imgOption, getWidth()/2,getHeight()/2+40, g.HCENTER|g.VCENTER);
//        }
        if(select==3){
            g.drawImage(imgHelp, getWidth()/2+2,getHeight()/2+58, g.HCENTER|g.VCENTER);
        }
        if(select==4){
            g.drawImage(imgExit, getWidth()/2-1,getHeight()/2+98, g.HCENTER|g.VCENTER);
        }
        
    }
}
